package com.woniuxy.automotivemanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.automotivemanagementsystem.entity.Car;
import com.woniuxy.automotivemanagementsystem.entity.News;
import com.woniuxy.automotivemanagementsystem.entity.vo.CarVo;
import com.woniuxy.automotivemanagementsystem.mapper.CarMapper;
import com.woniuxy.automotivemanagementsystem.service.CarService;
import com.woniuxy.automotivemanagementsystem.utils.PageResult;
import com.woniuxy.automotivemanagementsystem.utils.Result;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements CarService {
    /*
    * 条件查询所有
    * */
    @Override
    public Result queryCondition(CarVo vo) {
        LambdaQueryWrapper<Car> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(vo.getCname()!=null && !vo.getCname().trim().isEmpty(),Car::getCname,vo.getCname())
                .eq(vo.getBrand()!=null && !vo.getBrand().trim().isEmpty(),Car::getBrand,vo.getBrand())
                .eq(vo.getStatus()!=null,Car::getStatus,vo.getStatus())
                .le(vo.getDailyRate() !=null,Car::getDailyRate,vo.getDailyRate());
        //2.分页查询
        Page<Car> page = this.page(new Page<>(vo.getPageNum(),vo.getPageSize()), queryWrapper);
        //3.封装响应数据
        PageResult<Car> pageResult = new PageResult<>(page.getCurrent(), page.getSize(), page.getTotal(), page.getRecords());
        return Result.success(pageResult); //res.data.data.list
    }
}
